import math
import numpy as np


# x:列向量,dim:将列向量从1列映射到dim列,sigma自己设定的
def rbfmap(x, dim, sigma):
    X = np.zeros((x.shape[0], dim))
    for i in range(dim):
        s = 1
        for j in range(i):
            if j == 0:
                j = 1
            s = s * j
        t = sigma ** (2*i)

        for n in range(len(x)):
           xx1 = x[n, 0] * x[n, 0]
           e = math.exp(- xx1 / (2 * sigma ** 2))
           xx2 = x[n, 0] ** i
           s = math.sqrt(1 / (s * t)) * e * xx2
           X[n, i] = s
    return X


if __name__ == '__main__':
    x = [[1], [2], [3]]
    print(x)
    x = np.array(x)
    # rbfmap只能将一个向量映射到高维
    X = rbfmap(x, 2, 2)
    print(X)

